#coding=utf-8
__author__ = 'Meteor'

import logging
import setings
from logging.handlers import RotatingFileHandler
import os

logging.DEBUG

class Log:

    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(setings.LOG_LEVER)

        logfile = os.path.join(setings.BASE,'logs','api_frame.log')

        self.handler = logging.handlers.RotatingFileHandler(logfile, maxBytes=102400, backupCount=2,encoding='utf-8')
        self.handler.setLevel(setings.LOG_LEVER)
        if setings.isFileLog:
            self.logger.addHandler(self.handler)



        self.console_handler = logging.StreamHandler()
        self.console_handler.setLevel(setings.LOG_LEVER)
        if setings.isStream:
            self.logger.addHandler(self.console_handler)



        fmt = logging.Formatter("%(asctime)s %(filename)s  %(lineno)s  %(name)s  [%(levelname)s]:  %(message)s")
        self.handler.setFormatter(fmt)

    def get_log(self):
        return self.logger

logger = Log().get_log()
